package cn.seqdata.jpa;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.springframework.data.domain.Persistable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@MappedSuperclass
@JsonInclude(Include.NON_NULL)
public abstract class JpaNamed<ID extends Serializable> implements Persistable<ID> {
	private static final long serialVersionUID = 1L;

	protected ID id;
	private String name;

	public JpaNamed() {
		super();
	}

	public JpaNamed(ID id) {
		setId(id);
	}

	public JpaNamed(ID id, String name) {
		this(id);
		this.name = name;
	}

	public JpaNamed(JpaNamed<ID> object) {
		this(object.id, object.name);
	}

	@Transient
	@JsonIgnore
	@Override
	public boolean isNew() {
		return null == getId();
	}

	public void setId(ID id) {
		this.id = id;
	}

	@Column(name = "name", length = 80)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
